package com.ch.chatbot.domain.common;

import com.ch.chatbot.domain.model.enums.GptModelEnum;
import com.ch.chatbot.domain.model.vo.ChatGptTemplate;
import org.springframework.stereotype.Component;

import java.util.Arrays;
import java.util.Collections;

@Component
public class TemplateModelFactory {

    /**
     * 聊天问答场景
     */
    public ChatGptTemplate getQuestionAndAnswerTemplate(String question) {
        return ChatGptTemplate.builder()
                .model(GptModelEnum.TEXT_DAVINCI_003.getModel())
                .prompt("I am a highly intelligent question answering bot. If you ask me a question that is rooted in truth, I will give you the answer. If you ask me a question that is nonsense, trickery, or has no clear answer, I will respond with \\\"Unknown\\\"" + question)
                .temperature(0)
                .max_tokens(200)
                .top_p(1)
                .frequency_penalty(0)
                .presence_penalty(0)
                .stop(Collections.singletonList("\n"))
                .build();
    }

    /**
     * 将英文转换为标准英文
     */
    public ChatGptTemplate normalEnglish(String question) {
        return ChatGptTemplate.builder()
                .model(GptModelEnum.TEXT_DAVINCI_003.getModel())
                .prompt("Correct this to standard English:\n" + question)
                .temperature(0)
                .max_tokens(200)
                .top_p(1)
                .frequency_penalty(0)
                .presence_penalty(0)
                .build();
    }

    /**
     * 计算函数复杂度
     * The time complexity of this function is
     */
    public ChatGptTemplate computeComplex(String question) {
        return ChatGptTemplate.builder()
                .model(GptModelEnum.TEXT_DAVINCI_003.getModel())
                .prompt(question + "The time complexity of this function is")
                .temperature(0)
                .max_tokens(200)
                .top_p(1)
                .frequency_penalty(0)
                .presence_penalty(0)
                .stop(Collections.singletonList("\n"))
                .build();
    }

    /**
     * 解释复杂代码
     */
    public ChatGptTemplate explainComplexCode(String code) {
        return ChatGptTemplate.builder()
                .model(GptModelEnum.CODE_DAVINCI_OO2.getModel())
                .prompt(code + "Here's what the above class is doing")
                .temperature(0)
                .max_tokens(200)
                .top_p(1)
                .frequency_penalty(0)
                .presence_penalty(0)
                .stop(Collections.singletonList("\\\"\\\"\\\""))
                .build();
    }

    /**
     * 讽刺聊天机器人Marv
     */
    public ChatGptTemplate reluctantlyAnswer(String question) {
        return ChatGptTemplate.builder()
                .model(GptModelEnum.TEXT_DAVINCI_003.getModel())
                .prompt(DomainConstant.MARV + "is a chatbot that reluctantly answers questions with sarcastic responses: " + question)
                .temperature(0.5)
                .max_tokens(2000)
                .top_p(0.3)
                .frequency_penalty(0.5)
                .presence_penalty(0)
                .build();
    }

    /**
     * 通用处理
     */
    public ChatGptTemplate normalHandle(String question) {
        return ChatGptTemplate.builder()
                .model(GptModelEnum.TEXT_DAVINCI_003.getModel())
                .prompt("The following is a conversation with an AI assistant. The assistant is helpful, creative, clever, and very friendly: " + question)
                .temperature(0.9)
                .max_tokens(150)
                .top_p(1)
                .frequency_penalty(0)
                .presence_penalty(0.6)
                .stop(Arrays.asList(" Human ", " AI "))
                .build();
    }

}
